package com.cljz.peipei.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.ImageView;

import com.cljz.peipei.R;
import com.cljz.peipei.base.App;
import com.cljz.peipei.base.BaseActivity;
import com.cljz.peipei.base.Constant;
import com.cljz.peipei.utils.CommonUtils;
import com.cljz.peipei.utils.T;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.cache.SharedPref;
import cn.droidlover.xdroidmvp.router.Router;

public class SplashActivity extends BaseActivity {

    @BindView(R.id.iv_splash)
    ImageView ivSplash;

    @Override
    public void initData(Bundle savedInstanceState) {
        if (CommonUtils.isNetworkAvailable()) {
            // TODO: 2017/4/8
        } else {
            T.getInstance().showShort("网络不可用");
        }
        //这是一种可以创建多线程消息的函数
        ivSplash.postDelayed(new Runnable() {
            @Override
            public void run() {
                judgeTheFirstTime();
            }
        }, 1000);
    }

    private void judgeTheFirstTime() {
        if ("".equals(SharedPref.getInstance(App.getInstance()).getString(Constant.TOKEN, ""))) {
            Router.newIntent((Activity) App.getInstance()).to(BeginActivity.class).launch();
            Router.pop(SplashActivity.this);
        } else {
            Router.newIntent((Activity) App.getInstance()).to(MainActivity.class).launch();
            Router.pop(SplashActivity.this);
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    protected void setScreen() {
        //WindowManager是Android中一个重要的服务（Service ）。WindowManager Service 是全局的，是唯一的
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        //窗口显示时，隐藏所有的屏幕装饰（例如状态条）。使窗口占用整个显示区域。
        lp.flags = (WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setAttributes(lp);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

}
